package com.vancouver.knows.ui.activity.my;

import java.util.List;

import com.pangu.service.ActionException;
import com.pangu.task.IResultReceiver;
import com.pangu.task.mark.ATaskMark;
import com.vancouver.knows.R;
import com.vancouver.knows.ui.base.BaseActivity;
import com.vancouver.knows.ui.view.RichWebView;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.task.mark.MyUserNoticeTaskMark;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;


public class MyFeedbackAboutProcotolActivity extends BaseActivity implements IResultReceiver {
	private Context mContext;
	@Bind(R.id.common_tips)
	TextView  mCommonTips;
	@Bind(R.id.common_back)
	ImageView mCommonBack;
	@Bind(R.id.webview)
	RichWebView webview;
	private BusinessModule bModule;
	private ProgressDialog dialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_feedback_aboutus_useprotocol);
		mContext = MyFeedbackAboutProcotolActivity.this;
		setViews();
		setListeners();
	}
	
	private void sendFeedbackAboutUsProcotol(String pageType){
	    bModule = imContext.getBusinessModule();
	    MyUserNoticeTaskMark taskMark = bModule.getTaskMarkPool().getMyUserNoticeTaskMark();
	
		bModule.getServiceWrapper().myUserNotice(this, taskMark, pageType);
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void setViews() {
		Intent intent = getIntent();
		String tips = intent.getStringExtra("USER_NOTICE");
		mCommonTips.setText(tips);
		String pageType = intent.getStringExtra("PAGE_TYPE");
		sendFeedbackAboutUsProcotol(pageType);
	}
	
	private void setListeners(){
		mCommonBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	@Override
	public void receiveResult(ATaskMark taskMark, ActionException exception, Object trackerResult) {
		if (exception != null && !exception.getExMessage().equals("")){
			Toast.makeText(mContext, exception.getExMessage(), Toast.LENGTH_SHORT).show();
		}else{
			List<Object> contentList = bModule.getCacheManager().getMyUserNotice();
			if (contentList != null && contentList.size() > 0){
				webview.loadHtmlText((String)contentList.get(0));
			}
		}
		
	}
}